Skip to content

Port #60262: Include non-enumerable keys in __importStar helper #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 5, 2025

This PR ports TypeScript PR #60262 which updates the __importStar helper to include non-enumerable properties when creating namespace imports.

Changes Made

The __importStar helper has been updated from:

var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};

To:

var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();

Key Improvements

  1. Non-enumerable property support: Uses Object.getOwnPropertyNames() to capture both enumerable and non-enumerable properties
  2. Backwards compatibility: Falls back to the original for...in loop behavior when Object.getOwnPropertyNames is not available
  3. Performance optimization: Wraps the implementation in an IIFE to define the ownKeys function once

Files Modified

  • internal/printer/helpers.go - Updated the importStarHelper Text field
  • internal/transformers/commonjsmodule_test.go - Updated unit test expected output
  • Multiple baseline files and diff files updated to reflect the new helper output

Testing

All tests pass after accepting baseline changes. Many diff files were completely eliminated, indicating perfect matches between expected and actual output for those test cases.

Fixes #2.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Port #60262 Port #60262: Include non-enumerable keys in __importStar helper Jun 5, 2025
@Copilot Copilot AI requested a review from andrewbranch June 5, 2025 22:39
Copilot finished work on behalf of andrewbranch June 5, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port #60262
2 participants